<?php
$a_tablecolumns_namhoa_passport_permission = array(
    'name'    => 'passport_permission',
    'columns' => array(
        'permissionid'      ,
        'moduleactionid'    ,
        'permissionfor'     ,
        'permissionfortype' ,
        'permissionstatus'  ,
        'permissiontype'    ,
        'creatorid'         ,
        'updaterid'         ,
        'insertdate'        ,
        'updatedate'        ,
    ),
);

function get_columns_namhoa_passport_permission() {
    return array(
        'name'    => 'passport_permission',
        'columns' => array(
            'permissionid'      ,
            'moduleactionid'    ,
            'permissionfor'     ,
            'permissionfortype' ,
            'permissionstatus'  ,
            'permissiontype'    ,
            'creatorid'         ,
            'updaterid'         ,
            'insertdate'        ,
            'updatedate'        ,
        ),
    );
}

$f_permissionid      = 0 ;
$f_moduleactionid    = 0 ;
$f_permissionfor     = '';
$f_permissionfortype = '';
$f_permissionstatus  = '';
$f_permissiontype    = '';
$f_creatorid         = '';
$f_updaterid         = '';
$f_insertdate        = date('Y-m-d H:i:s');
$f_updatedate        = $f_insertdate;

class namhoa_passport_permission {
    public function __get($v_property) {
        return '';
    }
} 

$d_passport_permission = new namhoa_passport_permission();

if (isset($_REQUEST['permissionid'      ] )) { $f_permissionid      = $_REQUEST['permissionid'      ] ; }
if (isset($_REQUEST['moduleactionid'    ] )) { $f_moduleactionid    = $_REQUEST['moduleactionid'    ] ; }
if (isset($_REQUEST['permissionfor'     ] )) { $f_permissionfor     = $_REQUEST['permissionfor'     ] ; }
if (isset($_REQUEST['permissionfortype' ] )) { $f_permissionfortype = $_REQUEST['permissionfortype' ] ; }
if (isset($_REQUEST['permissionstatus'  ] )) { $f_permissionstatus  = $_REQUEST['permissionstatus'  ] ; }
if (isset($_REQUEST['permissiontype'    ] )) { $f_permissiontype    = $_REQUEST['permissiontype'    ] ; }

function make_filter_namhoa_passport_permission($s_field, $s_keyword) {
    $v_filter = '';

    if ($s_field != '' && $s_keyword != '') {
        switch ($s_field) {
            case 'permissionfor'     :
            case 'permissionfortype' :
            case 'permissionstatus'  :
            case 'permissiontype'    :
            case 'creatorid'         :
            case 'updaterid'         :
            case 'permissionid'      :
            case 'moduleactionid'    :
                $v_filter = "`$s_field` like '%$s_keyword%'";

                break;

            case 'insertdate'        :
            case 'updatedate'        :
                $v_thisday = $v_nextday = date('Y-m-d');

                if (strpos($s_keyword, '~') !== FALSE) {
                    $v_keywords = explode('~', $s_keyword)   ;
                    $v_thisday  = format_date($v_keywords[0]);
                    $v_nextday  = format_date($v_keywords[1]);
                }

                $v_filter = "(`$s_field` >= '$v_thisday 00:00:00' and `$s_field` <= '$v_nextday 23:59:59')";

                break;

        }
    }

    return $v_filter;
}

function make_advanced_filter_namhoa_passport_permission($s_field, $s_keyword) {
    $v_filter = '';

    if ($s_field != '' && $s_keyword != '') {
        switch ($s_field) {
            case 'permissionfor'     :
            case 'permissionfortype' :
            case 'permissionstatus'  :
            case 'permissiontype'    :
            case 'creatorid'         :
            case 'updaterid'         :
                $v_filter = "`$s_field` like '%$s_keyword%'";

                break;

            case 'permissionid'      :
            case 'moduleactionid'    :
                if (strpos($s_keyword, '~') !== FALSE) {
                    list($v_from, $v_to) = explode('~', $s_keyword, 2);
                
                    if (is_numeric($v_from)) {
                        $v_filter = $v_filter . "`$s_field` >= $v_from";
                    }
                
                    if (is_numeric($v_to)) {
                        $v_filter = $v_filter . (empty($v_filter) ? '' : ' and ') . "`$s_field` <= $v_to";
                    }
                
                    $v_filter = empty($v_filter) ? '' : "($v_filter)";
                }
                elseif (is_numeric($s_keyword)) {
                    $v_filter = "`$s_field` = $s_keyword";
                }

                break;

            case 'insertdate'        :
            case 'updatedate'        :
                if (strpos($s_keyword, '~') !== FALSE) {
                    list($v_fromday, $v_today) = explode('~', $s_keyword, 2);
                
                    if (validate_date($v_fromday)) {
                        $v_filter = $v_filter . "`$s_field` >= '$v_fromday 00:00:00'";
                    }
                
                    if (validate_date($v_today)) {
                        $v_filter = $v_filter . (empty($v_filter) ? '' : ' and ') . "`$s_field` <= '$v_today 23:59:59'";
                    }
                
                    $v_filter = empty($v_filter) ? '' : "($v_filter)";
                }
                elseif (validate_date($s_keyword)) {
                    $v_filter = "(`$s_field` >= '$s_keyword 00:00:00' and `$s_field` <= '$s_keyword 23:59:59')";
                }

                break;

        }
    }

    return $v_filter;
}

function build_filter_namhoa_passport_permission($s_field) {
    echo '<option value="permissionid"'      , ($s_field == 'permissionid'       ? ' selected="selected"' : ''), '> Permission ID       </option>';
    echo '<option value="moduleactionid"'    , ($s_field == 'moduleactionid'     ? ' selected="selected"' : ''), '> Module Action ID    </option>';
    echo '<option value="permissionfor"'     , ($s_field == 'permissionfor'      ? ' selected="selected"' : ''), '> Permission For      </option>';
    echo '<option value="permissionfortype"' , ($s_field == 'permissionfortype'  ? ' selected="selected"' : ''), '> Permission For Type </option>';
    echo '<option value="permissionstatus"'  , ($s_field == 'permissionstatus'   ? ' selected="selected"' : ''), '> Permission Status   </option>';
    echo '<option value="permissiontype"'    , ($s_field == 'permissiontype'     ? ' selected="selected"' : ''), '> Permission Type     </option>';
    echo '<option value="creatorid"'         , ($s_field == 'creatorid'          ? ' selected="selected"' : ''), '> Người Tạo           </option>';
    echo '<option value="updaterid"'         , ($s_field == 'updaterid'          ? ' selected="selected"' : ''), '> Người Cập Nhật      </option>';
    echo '<option value="insertdate"'        , ($s_field == 'insertdate'         ? ' selected="selected"' : ''), '> Người Tạo           </option>';
    echo '<option value="updatedate"'        , ($s_field == 'updatedate'         ? ' selected="selected"' : ''), '> Người Cập Nhật      </option>';
}

function build_advanced_filter_namhoa_passport_permission($s_field, $a_hide = array()) {
    if (empty($a_hide)) {
        return build_filter_namhoa_passport_permission($s_field);
    }

    $a_columns = array(
        'permissionid'      => 'Permission ID'       ,
        'moduleactionid'    => 'Module Action ID'    ,
        'permissionfor'     => 'Permission For'      ,
        'permissionfortype' => 'Permission For Type' ,
        'permissionstatus'  => 'Permission Status'   ,
        'permissiontype'    => 'Permission Type'     ,
        'creatorid'         => 'Người Tạo'           ,
        'updaterid'         => 'Người Cập Nhật'      ,
        'insertdate'        => 'Người Tạo'           ,
        'updatedate'        => 'Người Cập Nhật'      ,
    );

    $a_hide    = array_combine($a_hide, $a_hide);
    $a_columns = array_diff_key($a_columns, $a_hide);

    foreach ($a_columns as $v_columnname => $v_columncomment) {
        echo '<option value="', $v_columnname, '"', ($s_field == $v_columnname ? ' selected="selected"' : ''), '>', $v_columncomment, '</option>';
    }
}
?>